<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/7/12
 * Time: 16:00
 */

namespace common\models\Service;


use common\models\CommonFunction;
use wap\models\Service\WechatModel;

class SendWxMessage {

    /*
     * 充值成功通知
     */
    public static function charge($openID, $money, $desc = ''){
        if(empty($openID))  return true;
        $chargeTemplete = 'aVg-Ti-jTME172lap6XoOen7oGSuw-01VjbXcBJIUg8';
        $options = array(
            'token'=>\Yii::$app->params['token'], //填写你设定的key
            'appid'=> \Yii::$app->params['appID'],
            'appsecret'=>\Yii::$app->params['appSecret']
        );
        $wechatModel = new WechatModel($options);
        $color = \Yii::$app->params['fontTempleteColor'];
        $_desc = '恭喜您充值成功！';
        $desc && $_desc = $desc;
        $data = array('touser'=>$openID,
            'template_id'=>$chargeTemplete,
            'url'=>\Yii::$app->params['host']."/my-account.html",
            'topcolor'=>\Yii::$app->params['templeteColor'],
            'data'=>array(
                'first'=>array('value'=>$_desc),
                'keyword1'=>array('value'=>$money,'color'=>$color),
                'keyword2'=>array('value'=>date('Y-m-d H:i'),'color'=>$color),
                'remark'=>array('value'=>'如您有任何问题，欢迎来电咨询'.\Yii::$app->params['tel'],'color'=>$color)
            )
        );
        $wechatModel->sendTemplateMessage($data);
    }


    /*
    * 提现成功通知
    */
    public static function cash($openID, $money, $card){
        if(empty($openID))  return true;
        $chargeTemplete = 'tmIz8a4uguzIOsAGFoV_kShj3qUYFONhpQwB9d1ywNI';
        $options = array(
            'token'=>\Yii::$app->params['token'], //填写你设定的key
            'appid'=> \Yii::$app->params['appID'],
            'appsecret'=>\Yii::$app->params['appSecret']
        );
        $wechatModel = new WechatModel($options);
        $color = \Yii::$app->params['fontTempleteColor'];
        $data = array('touser'=>$openID,
            'template_id'=>$chargeTemplete,
            'url'=>\Yii::$app->params['host']."/my-account.html",
            'topcolor'=>\Yii::$app->params['templeteColor'],
            'data'=>array(
                'first'=>array('value'=>'恭喜您提现成功！'),
                'keyword1'=>array('value'=>'银行卡尾号'.$card,'color'=>$color),
                'keyword2'=>array('value'=>$money,'color'=>$color),
                'keyword3'=>array('value'=>date('Y-m-d H:i'),'color'=>$color),
                'remark'=>array('value'=>'您提现的金额已到账，请注意查收。如您有任何问题，欢迎来电咨询'.\Yii::$app->params['tel'],'color'=>$color)
            )
        );
        $wechatModel->sendTemplateMessage($data);
    }

    /*
   * 提现成功通知
   */
    public static function cashNotice($openID, $money){
        if(empty($openID))  return true;
        $chargeTemplete = 'kHjdWL_BupBH6pG-BZql1c9-_rGhismOB_c3cLYd2BE';
        $options = array(
            'token'=>\Yii::$app->params['token'], //填写你设定的key
            'appid'=> \Yii::$app->params['appID'],
            'appsecret'=>\Yii::$app->params['appSecret']
        );
        $wechatModel = new WechatModel($options);
        $color = \Yii::$app->params['fontTempleteColor'];
        $poundage = '0.00';
        $money < 1000 && $poundage = '3.00';
        $money = CommonFunction::formatMoney($money);
        $data = array('touser'=>$openID,
            'template_id'=>$chargeTemplete,
            'url'=>\Yii::$app->params['host']."/my-account.html",
            'topcolor'=>\Yii::$app->params['templeteColor'],
            'data'=>array(
                'first'=>array('value'=>"您的账户提现支出人民币{$money}元！"),
                'keyword1'=>array('value'=>date('Y-m-d H:i'),'color'=>$color),
                'keyword2'=>array('value'=>$money,'color'=>$color),
                'keyword3'=>array('value'=>$poundage,'color'=>$color),
                'remark'=>array('value'=>"工作日10:30之前提交的，会在当天12:00之前到账。\n工作日10:30-14:00之间提交的，会在当天下午17:00之前到账。\n工作日14:30之后或是节假日提现，顺延到下个工作日到账。\n如您有任何问题，欢迎来电咨询".\Yii::$app->params['tel'],'color'=>$color)
            )
        );
        $wechatModel->sendTemplateMessage($data);
    }

    /*
   * 投资成功通知
   */
    public static function invest($param){
        if(empty($param['openID']))  return true;
        $chargeTemplete = 'k2qWXj-EVxUDUEfwYbGpMUDheu93VwHPMEESxNjdwCA';
        $options = array(
            'token'=>\Yii::$app->params['token'], //填写你设定的key
            'appid'=> \Yii::$app->params['appID'],
            'appsecret'=>\Yii::$app->params['appSecret']
        );
        $wechatModel = new WechatModel($options);
        $color = \Yii::$app->params['fontTempleteColor'];
        $remark = '如您有任何问题，欢迎来电咨询'.\Yii::$app->params['tel'];
        isset($param['remark']) && $remark = $param['remark'];
        $data = array('touser'=>$param['openID'],
            'template_id'=>$chargeTemplete,
            'url'=>\Yii::$app->params['host'].\Yii::$app->urlManager->createUrl(['invest/index', 'id' => $param['id']]),
            'topcolor'=>\Yii::$app->params['templeteColor'],
            'data'=>array(
                'first'=>array('value'=>'您已成功投资，明日开始计息。'),
                'keyword1'=>array('value'=>$param['name'],'color'=>$color),
                'keyword2'=>array('value'=>$param['rate'],'color'=>$color),
                'keyword3'=>array('value'=>$param['day'],'color'=>$color),
                'keyword4'=>array('value'=>$param['money'],'color'=>$color),
                'keyword5'=>array('value'=>$param['accrual'],'color'=>$color),
                'remark'=>array('value'=>$remark,'color'=>'#fe327a')
            )
        );
        $wechatModel->sendTemplateMessage($data);
    }

    /*
   * 投资到期通知
   */
    public static function success($openID, $money, $name){
        if(empty($openID))  return true;
        $chargeTemplete = 'f1iiYhrVaDWEF-mGesnjtsndeuEUPCm658-O5Nlq8WU';
        $options = array(
            'token'=>\Yii::$app->params['token'], //填写你设定的key
            'appid'=> \Yii::$app->params['appID'],
            'appsecret'=>\Yii::$app->params['appSecret']
        );
        $wechatModel = new WechatModel($options);
        $color = \Yii::$app->params['fontTempleteColor'];
        $data = array('touser'=>$openID,
            'template_id'=>$chargeTemplete,
            'url'=>\Yii::$app->params['host']."/me/invest.html",
            'topcolor'=>\Yii::$app->params['templeteColor'],
            'data'=>array(
                'first'=>array('value'=>'您投资的'.$name.'，收益已到账！'),
                'income_amount'=>array('value'=>CommonFunction::formatMoney($money).'元','color'=>$color),
                'income_time'=>array('value'=>date('Y-m-d H:i'),'color'=>$color),
                'remark'=>array('value'=>'如您有任何问题，欢迎来电咨询'.\Yii::$app->params['tel'],'color'=>$color)
            )
        );
        return $wechatModel->sendTemplateMessage($data);
    }

    //红包
    public static function hongbao($openID, $money, $tile = '您获取现金红包', $content = ''){
        if(empty($openID))  return true;
        $chargeTemplete = 'p9nwA_gFTI2yUOKuLEz-Y1WlI5mpu9jjcTlb2DWoS00';
        $options = array(
            'token'=>\Yii::$app->params['token'], //填写你设定的key
            'appid'=> \Yii::$app->params['appID'],
            'appsecret'=>\Yii::$app->params['appSecret']
        );
        $wechatModel = new WechatModel($options);
        $color = \Yii::$app->params['fontTempleteColor'];
        $remark = '如您有任何问题，欢迎来电咨询'.\Yii::$app->params['tel'];
        $content && $remark = $content;
        $data = array('touser'=>$openID,
            'template_id'=>$chargeTemplete,
            'url'=>\Yii::$app->params['host']."/pocket.html",
            'topcolor'=>\Yii::$app->params['templeteColor'],
            'data'=>array(
                'first'=>array('value'=>$tile),
                'present_income'=>array('value'=>$money ,'color'=>$color),
                'remark'=>array('value'=>$remark,'color'=>$color)
            )
        );
        return $wechatModel->sendTemplateMessage($data);
    }

    //红包
    public static function integral($openID, $money, $tile = '', $content = ''){
        if(empty($openID))  return true;
        $chargeTemplete = 'TNnOT6U2KiMhyz4_6mDU1IdEWCelYi-UqA3I1-9TLuA';
        $options = array(
            'token'=>\Yii::$app->params['token'], //填写你设定的key
            'appid'=> \Yii::$app->params['appID'],
            'appsecret'=>\Yii::$app->params['appSecret']
        );
        $wechatModel = new WechatModel($options);
        $color = \Yii::$app->params['fontTempleteColor'];
        $remark = '如您有任何问题，欢迎来电咨询'.\Yii::$app->params['tel'];
        $data = array('touser'=>$openID,
            'template_id'=>$chargeTemplete,
            'url'=>\Yii::$app->params['host']."/integral.html",
            'topcolor'=>\Yii::$app->params['templeteColor'],
            'data'=>array(
                'first'=>array('value'=>$tile),
                'keyword1'=>array('value'=>$money ,'color'=>$color),
                'keyword2'=>array('value'=>$content ,'color'=>$color),
                'remark'=>array('value'=>$remark,'color'=>$color)
            )
        );
        return $wechatModel->sendTemplateMessage($data);
    }

}